package fr.dauphine.spring.bo;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.stereotype.Component;

@Component
@Entity
@Table(name = "ADRESSE")
@SQLDelete(sql = "update ADRESSE set deleted = 'TRUE' where id = ? and version = ?")
@Where(clause = "deleted <> 'TRUE'")
public class Adresse extends BO implements Serializable, Comparable<Adresse> {

	private static final long serialVersionUID = 1L;
	@ManyToOne(fetch = FetchType.EAGER)
	private Client client;

	private String numero;
	private String rue;
	private String postCode;
	private String ville;
	private String pays;
	private String type;
	private String numTel;
	private String email;

	// private int numero = 10;
	// private String rue = "blalbla";
	// private int postCode = 98220;
	// private String ville = "meuhmeuh";
	// private String pays = "wonderland";
	// private String type = "Perso";
	// private int numTel = 0645545445;
	// private String email = "fldkjshf@fslj.com";

	public Adresse() {

	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getRue() {
		return rue;
	}

	public void setRue(String rue) {
		this.rue = rue;
	}

	public String getNumero() {
		return numero;
	}

	public void setNumero(String numero) {
		this.numero = numero;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public String getNumTel() {
		return numTel;
	}

	public void setNumTel(String numTel) {
		this.numTel = numTel;
	}

	public String getVille() {
		return ville;
	}

	public void setVille(String ville) {
		this.ville = ville;
	}

	public String getPays() {
		return pays;
	}

	public void setPays(String pays) {
		this.pays = pays;
	}

	@Override
	public int compareTo(Adresse o) {
		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Adresse) {
			final Adresse adresse = (Adresse) obj;
			return (adresse.numero == this.numero && adresse.rue.equals(this.rue)
					&& adresse.postCode == this.postCode && adresse.ville.equals(this.ville)
					&& adresse.pays.equals(this.pays) && adresse.email.equals(this.email)
					&& adresse.numTel == this.numTel && adresse.type.equals(this.type));
		} else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (id != null) ? id.hashCode() : 0;
	}

	@Override
	public String toString() {
		return numero + ", " + rue + ", " + postCode + ", " + ville + ": " + pays;
	}
}
